Xbasic

Methods for Controlling Menus at Runtime

Description

Using the Xbasic .MENUITEMENABLE() method, you can enable and disable menu items in form, browse and print preview windows. Also, using .MENUITEMCHECK(), you can check and un-check menu items.

The Menu Maker allows you to define expressions that control whether a menu item is enabled/disabled, or checked/un-checked. If you use the .MENUITEMENABLE(), or .MENUITEMCHECK() methods, then the expressions defined as Part of the menu definition are overridden (i.e. they are ignored). If you want to turn the override off (and return to the state of the menus being controlled by the enable and check expressions), you can use the .MENUITEMRESET() method.

For example, assume that you have a form called Customer. You have designed a custom menu for this form and one of the menu items on this custom menu is "Print Sales Report". To disable (i.e., gray) this menu item, you would use this Xbasic statement:

:customer.MenuItemEnable("Print Sales Report", .f.)
If the menu item name includes an accelerator key, then the string must also include the accelerator key. For example, "&Print Sales Report". If the menu item name includes a hot key, then that too must be included.

The hot key is separated from the menu item name with a tab. E.g.

:customer.MenuItemEnable("Find &Text..." + chr(9) + "Ctrl + L",.f.)

Xbasic Script Context

When a script that is attached to a menu is run, the script has the same context as the active window. The aliases this and topparent, when used in a script that is attached to a menu, refers to the active window.

See Also